package com.tchepannou.limbe.gae.dao;

import com.google.appengine.api.datastore.Key;
import com.tchepannou.limbe.model.Model;

import java.util.Iterator;
import java.util.List;

/**
 * Implementation of {@link Iterator}
 * @param <T>
 */
class PersistentIterator<T extends Model>
    implements Iterator<T>
{
    //-- Attributes
    private AbstractGaeDao _dao;
    private Iterator<Key> _it;

    //-- Constructor
    public PersistentIterator (List<Key> keys, AbstractGaeDao dao)
    {
        _it = keys.iterator();
        _dao = dao;
    }


    //-- Iterator overrides
    public T next()
    {
        Key key = _it.next ();
        T result = (T)_dao.findByKey(key);
        return result;
    }

    public boolean hasNext()
    {
        return _it.hasNext();
    }

    public void remove()
    {
        throw new UnsupportedOperationException ();
    }
}
